package com.example.g5project.controller;

import com.example.g5project.entity.frontEndObject.NewChat;
import com.example.g5project.exception.EntityNotExistException;
import com.example.g5project.others.ResponseValue;
import com.example.g5project.service.NewChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author Hu Zirui
 * @version 1.0.0
 * @ClassName ConsultantController.java
 * @Description TODO
 * @createTime 2022年03月23日 15:33:00
 */
@Api("全新的聊天接口操作")
@CrossOrigin
@RestController
@RequestMapping(value = "/newchat")
public class NewChatController {
    private final NewChatService newChatService;

    public NewChatController(NewChatService newChatService) {
        this.newChatService = newChatService;
    }

    @ApiOperation("根据用户姓名和日期搜索某个咨询师聊天记录梗概")
    @RequestMapping(method = RequestMethod.GET, value = "/getMsgByNameAndDate/{name}/{date}")
    public ResponseValue<?> getChatMsgByNameAndDate(@ApiParam(value = "需要增加信息的咨询师姓名", required = true, example = "-947912704") @PathVariable String name, @PathVariable String date) {
        return ResponseValue.success(newChatService.getChatMsgByNameAndDate(name, date));
    }

    @ApiOperation("插入一条聊天记录梗概")
    @RequestMapping(method = RequestMethod.GET, value = "/addNewMsg")
    public ResponseValue<?> addNewChat(@RequestBody NewChat newChat) {
        newChatService.addNewChat(newChat);
        return ResponseValue.success("success");
    }

    @ApiOperation("根据咨询师姓名返回全部的聊天记录梗概")
    @RequestMapping(method = RequestMethod.GET, value = "/getAllMsgByName/{name}")
    public ResponseValue<?> getAllChatMsgByConsultantName(@ApiParam(value = "需要增加信息的咨询师姓名", required = true, example = "-947912704") @PathVariable String name) throws ParseException {
        return ResponseValue.success(newChatService.getAllChatMsgByConsultantNameStr(name));
    }

    @ApiOperation("根据id更新某一条聊天记录梗概, 即输入咨询师的评价信息")
    @RequestMapping(method = RequestMethod.GET, value = "/updateNewChatComment/{id}/{content}")
    public ResponseValue<?> updateNewChatComment(@ApiParam(value = "需要增加信息的咨询师姓名", required = true, example = "-947912704") @PathVariable Integer id, @PathVariable String content) {
        newChatService.updateNewChatComment(id, content);
        return ResponseValue.success("success");
    }

    @ApiOperation("根据id返回结束时间, 通过结束时间判断会话是否结束")
    @RequestMapping(method = RequestMethod.GET, value = "/getEndTime/{id}")
    public ResponseValue<?> getEndTimeById(@PathVariable Integer id) {
        return ResponseValue.success(newChatService.getEndTimeById(id));
    }

    @ApiOperation("返回全部的聊天记录梗概")
    @RequestMapping(method = RequestMethod.GET, value = "/getAllMsg")
    public ResponseValue<?> getAllMsg() {
        return ResponseValue.success(newChatService.getAllMsgStr());
    }

    @ApiOperation("返回最新的聊天记录梗概")
    @RequestMapping(method = RequestMethod.GET, value = "/getRecentMsg")
    public ResponseValue<?> getRecentMsg() {
        return ResponseValue.success(newChatService.getRecentMsg());
    }

    @ApiOperation("返回最新的聊天记录梗概结束时间")
    @RequestMapping(method = RequestMethod.GET, value = "/getRecentMsgEndTime")
    public ResponseValue<?> getRecentMsgEndTime() {
        return ResponseValue.success(newChatService.getRecentMsgEndTime());
    }

    @ApiOperation("根据id更新某一条聊天记录梗概, 即输入咨询师的评价信息")
    @RequestMapping(method = RequestMethod.GET, value = "/updateNewChatByID/{id}")
    public ResponseValue<?> updateNewChatCommentByID(@PathVariable Integer id, @RequestBody @Validated NewChat newChat) throws EntityNotExistException {
        newChat.setId(id);
        newChatService.updateNewChatCommentByID(id, newChat);
        return ResponseValue.success("success update");
    }

}
